/**
 * @description: 钉钉授权登录及用户信息获取
 * @version: 0.0.1
 * @author: z..
 * @Date: 2023-06-12 18:16:39
 */

import { Inject, Controller, Get, Query, Post, Body } from '@midwayjs/core';
import { DingtalkAuthService } from '../service/dingtalk.auth.service';
import { AuthDTO } from '../dto/dingtalk.auth';
import { Context } from '@midwayjs/koa';
import { NotLogin } from "../decorator/not.login";
import { NotAuth } from "../decorator/not.auth";

@Controller('/api/v1/login')
export class DingtalkAuth {
  @Inject()
  ctx: Context;
  
  @Inject()
  DingtalkAuthService: DingtalkAuthService;

  /**
   * @summary 钉钉OAuth登录授权页面链接获取
   * @description 钉钉OAuth登录授权页面链接获取
   * @router get /api/v1/login/getRedirectUri
   * @response 200 baseResponse 返回结果
   */
  @NotLogin()
  @NotAuth()
  @Get('/getRedirectUri')
  async getRedirectUri(@Query('state') state: string) {
    return await this.DingtalkAuthService.getRedirectUri(state);
  }

  /**
   * @summary 授权code换取token并获取用户信息
   * @description 授权code换取token并获取用户信息
   * @router post /api/v1/login/getUserInfo
   * @response 200 baseResponse 返回结果
   */
  @NotLogin()
  @NotAuth()
  @Post('/getUserInfo')
  async getUserInfo(@Body() data: AuthDTO) {
    return await this.DingtalkAuthService.getUserInfo(data);
  }

}
